#ifndef MOON_COMMON_MUTEX_H_
#define MOON_COMMON_MUTEX_H_
#include <cstdint>
#include <pthread.h>
#include <sys/time.h>
#include <unistd.h>
#include <cassert>
#include <cmath>

namespace mono {

enum class MutexType {
    FAST,                ///<! no operation
    ERRORCHECK,          ///<! check error
    RECURSIVE            ///<! allow recursive locking
};

class Mutex{

public:
      friend class Cond;
public:

  Mutex();

  explicit Mutex(MutexType type);

  ~Mutex();

  void lock();

  bool lock_try();

  bool lock_try(int64_t usec);

  void unlock();
private:
  pthread_mutex_t _mutex;
};

/*
  help class for no lock
  */
class NullMutex{
public:
    NullMutex(){ }
    explicit NullMutex(MutexType type) { (void)type; }
    ~NullMutex() { }

    void lock() { }
    void lock_try() { }
    bool lock_try(int64_t usec) {(void)usec; return true; }
    void unlock(){ }
};

}
#endif